<?php
error_reporting(0);
session_start();

include_once "src/model/Consultant.php";
include_once "src/controller/regmanagement/AccountManager.php";
include_once "src/controller/regmanagement/MiscellaneousManager.php";
include_once "src/model/ProvidedService.php";

try {
    $months = array();
    $months["0"] = "q";
    $months["01"] = "January";
    $months["02"] = "February";
    $months["03"] = "March";
    $months["04"] = "April";
    $months["05"] = "May";
    $months["06"] = "June";
    $months["07"] = "July";
    $months["08"] = "August";
    $months["09"] = "September";
    $months["10"] = "October";
    $months["11"] = "November";
    $months["12"] = "December";

    $months2 = array();
    $months2["January"] = "01";
    $months2["February"] = "02";
    $months2["March"] = "03";
    $months2["April"] = "04";
    $months2["May"] = "05";
    $months2["June"] = "06";
    $months2["July"] = "07";
    $months2["August"] = "08";
    $months2["September"] = "09";
    $months2["October"] = "10";
    $months2["November"] = "11";
    $months2["December"] = "12";

    if (isset($_GET["preview"])) {
        $providedServicesTemp1 = explode("&", $_POST["userServicesProvidedString"]);

        $providedServices = array();
        for ($i = 0; $i < count($providedServicesTemp1) - 1; $i++) {
            $providedServicesTemp2 = explode("-", $providedServicesTemp1[$i]);

            $tempServingSince1 = explode(", ", $providedServicesTemp2[1]);

            $tempServingSince = $tempServingSince1[1] . "-" . $months2[$tempServingSince1[0]] . "-01";
            
            $providedServiceTemp = new ProvidedService($providedServicesTemp2[0], $tempServingSince);
            $providedServiceTemp->setServiceName(MiscellaneousManager::getServiceName($providedServicesTemp2[0]));
            $providedServices[$i] = $providedServiceTemp;
        }

        $user = new Consultant();

        $user->setConsultantId($_POST["consultantId"]);
        $user->setEmail($_SESSION["email"]);
        $user->setPassword($_POST["password"]);
        $user->setAccountTypeId($_POST["accountTypeId"]);
        $user->setCompanyName($_POST["companyName"]);
        $user->setPhysicalAddress($_POST["physicalAddress"]);
        $user->setPhysicalCity($_POST["physicalCity"]);
        $user->setPhysicalStateId($_POST["physicalStateId"]);
        $user->setPhysicalZipCode($_POST["physicalZipCode"]);
        $user->setMailingAddress($_POST["mailingAddress"]);
        $user->setMailingCity($_POST["mailingCity"]);
        $user->setMailingStateId($_POST["mailingStateId"]);
        $user->setMailingZipCode($_POST["mailingZipCode"]);
        $user->setTelephone($_POST["telephone"]);
        $user->setTelephoneExt($_POST["telephoneExt"]);
        $user->setCellphone($_POST["cellphone"]);
        $user->setWebsite($_POST["website"]);
        $user->setServices($providedServices);
        $user->setK12ClienteleIndicator($_POST["k12ClienteleIndicator"]);
        $user->setHigherEducationClienteleIndicator($_POST["higherEducationClienteleIndicator"]);
        $user->setServicesOfferedDescription($_POST["servicesOfferedDescription"]);
        $user->setBackgroundDescription($_POST["backgroundDescription"]);
        $user->setEducationDescription($_POST["educationDescription"]);
        $user->setExperienceDescription($_POST["experienceDescription"]);
        $user->setComplaintIndicator($_POST["complaintIndicator"]);
        $user->setPendingLitigationIndicator($_POST["pendingLitigationIndicator"]);
        $user->setNoneIndicator($_POST["noneIndicator"]);
        $user->setProfileSubmittedIndicator($_POST["profileSubmittedIndicator"]);
        $user->setProfileFirstName($_POST["firstName"]);
        $user->setProfileLastName($_POST["lastName"]);
        $user->setProfileEmail($_POST["email"]);
    } else {
        $user = AccountManager::getConsultant($_GET["accountEmail"]);
    }
    
} catch (Exception $e) {
    echo $e->getMessage();
}
?>
<div style="height:30px;background-color:#CCCCCC;padding-top:3px;padding-right:25px;text-align:right;">
    <?php
        if (!isset($_GET["preview"])) {
    ?>
            <a href="printConsultantDetailInformationInclude.php?email=<?php echo $user->getEmail();?>" 
               target="_blank">
                <img src="images/icons/printIcon.png"
                     alt="printIcon"
                     style="border:none;" />
            </a>
    <?php        
        }
    ?>
</div>
<div style="background-color:#FFFFFF;font-family:Verdana;text-align:left;width:715px;height:400px;overflow:auto;padding-top:10px;padding-left:5px;">
    <div style="float:left;width:660px;">
        <div style="font-size:12px;font-weight:bold;">Consultant Name:</div>
        <div style="font-size:30px;"><?php echo $user->getProfileLastName() . ", " . $user->getProfileFirstName();?></div>
    </div>
    <div style="float:left;padding-top:10px;width:660px;">
        <div style="font-size:12px;font-weight:bold;">Name of Company:</div>
        <div style="font-size:24px;"><?php echo $user->getCompanyName();?></div>
    </div>
    <div style="float:left;padding-top:10px;width:660px;">
        <div style="float:left;">
            <div style="font-size:12px;font-weight:bold;padding-bottom:5px;">Mailing Address:</div>
            <div style="border: 1px solid #CCCCCC;background-color:#F2F5F9;padding:5px;">
                <table border="0"
                       cellpadding="0"
                       cellspacing="0"
                       style="font-family:Verdana;font-size:12px;font-weight:normal;width:300px;">
                    <tbody>
                        <tr>
                            <td id="mailingStreetLabel"
                                colspan="3"
                                style="padding-bottom:2px;padding-top:0px;padding-left:5px;font-weight:bold;">Street:</td>
                        </tr>
                        <tr>
                            <td colspan="3" style="padding-left:5px;">
                                <?php echo $user->getMailingAddress();?>
                            </td>
                        </tr>
                        <tr>
                            <td id="mailingCityLabel"
                                style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                City:
                            </td>
                            <td id="mailingStateIdLabel"
                                style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                State:
                            </td>
                            <td id="mailingZipCodeLabel"
                                style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                Zip Code:
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-left:5px;">
                                <?php echo $user->getMailingCity();?>
                            </td>
                            <td style="padding-left:5px;">
                                <?php
                                    try {
                                        echo MiscellaneousManager::getStateName($user->getMailingStateId());
                                    } catch (Exception $e) {
                                        echo "Not Provided";
                                    }
                                ?>
                            </td>
                            <td style="padding-left:5px;">
                                <?php
                                    try {
                                        echo (($user->getMailingZipCode() == "0")) ? "00000" : $user->getMailingZipCode();
                                    } catch (Exception $e) {
                                        echo "Not Provided";
                                    }
                                ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div style="float:right;">
            <div style="font-size:12px;font-weight:bold;padding-bottom:5px;">Physical Address:</div>
            <div style="border: 1px solid #CCCCCC;background-color:#F2F5F9;padding:5px;">
                <?php
                if (($user->getPhysicalAddress() == "") ||
                    ($user->getPhysicalCity() == "") ||
                    ($user->getPhysicalStateId() == "") ||
                    ($user->getPhysicalZipCode() == "")) {

                ?>
                    <div style="text-align:center;font-family:Verdana;font-size:12px;font-weight:normal;width:300px;height:70px;">
                        <br />Not Provided
                    </div>
                <?php
                } else {
                ?>
                    <table border="0"
                           cellpadding="0"
                           cellspacing="0"
                           style="font-family:Verdana;font-size:12px;font-weight:normal;width:300px;">
                        <tbody>
                            <tr>
                                <td id="physicalStreetLabel"
                                    colspan="3"
                                    style="padding-bottom:2px;padding-top:0px;padding-left:5px;font-weight:bold;">Street:</td>
                            </tr>
                            <tr>
                                <td colspan="3" style="padding-left:5px;">
                                    <?php echo $user->getPhysicalAddress();?>
                                </td>
                            </tr>
                            <tr>
                                <td id="physicalCityLabel"
                                    style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                    City:
                                </td>
                                <td id="physicalStateIdLabel"
                                    style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                    State:
                                </td>
                                <td id="physicalZipCodeLabel"
                                    style="padding-bottom:2px;padding-top:3px;padding-left:5px;font-weight:bold;">
                                    Zip Code:
                                </td>
                            </tr>
                            <tr>
                                <td style="padding-left:5px;">
                                    <?php echo $user->getPhysicalCity();?>
                                </td>
                                <td style="padding-left:5px;">
                                    <?php echo MiscellaneousManager::getStateName($user->getPhysicalStateId()); ?>
                                </td>
                                <td style="padding-left:5px;">
                                    <?php echo (($user->getPhysicalZipCode() == "0")) ? "00000" : $user->getPhysicalZipCode(); ?>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                <?php
                }
                ?>
            </div>
        </div>
    </div>
    <div style="padding-top:10px;float:left;width:660px;">
        <div style="float:left;width:300px;">
            <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Business Phone:</div>
            <div style="font-size:12px;">
                <?php echo $user->getTelephone();?><?php echo ($user->getTelephoneExt() == "") ? "" : " Ext. " . $user->getTelephoneExt() ?>
            </div>
        </div>
        <div style="float:right;width:310px;">
            <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Cell Phone:</div>
            <div style="font-size:12px;">
                <?php echo (($user->getCellphone() == "")) ? "Not Provided" : $user->getCellphone(); ?>
            </div>
        </div>
    </div>
    <div style="padding-top:10px;float:left;width:660px;">
        <div style="float:left;width:300px;">
            <div style="font-size:12px;font-weight:bold;">Email Address:</div>
            <div style="font-size:12px;"><?php echo $user->getProfileEmail();?></div>
        </div>
        <div style="float:right;width:310px;">
            <div style="font-size:12px;font-weight:bold;">Website Address:</div>
            <div style="font-size:12px;">
            <?php echo (($user->getWebsite() == "")) ? "Not Provided" : $user->getWebsite(); ?>
            </div>
        </div>
    </div>
    <div style="padding-top:10px;float:left;width:660px;">
        <div style="float:left;font-size:12px;font-weight:bold;padding-bottom:2px;">Services Offered:</div>
        <div style="float:left;padding:10px;border:1px solid #CCCCCC;width:660px;">
            <div style="float:left;font-size:12px;padding:0px;">
                <table class="consultantProvidedServicesTable">
                    <thead>
                        <tr>
                            <th>Service</th>
                            <th>Serving Since</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $consultantServices = $user->getServices();
                        for ($i = 0 ; $i < count($consultantServices) ; $i++) {
                            $tempService = $consultantServices[$i];

                            $tempServiceSinceParseDate = explode("-", $tempService->getServingSince());

                            $tempServingSince = $months[$tempServiceSinceParseDate[1]] . ", " . $tempServiceSinceParseDate[0];

                            if (($i % 2) == 0) {
                        ?>
                            <tr>
                                <td><?php echo $tempService->getServiceName(); ?></td>
                                <td><?php echo $tempServingSince; ?></td>
                            </tr>
                        <?php
                            } else {
                        ?>
                            <tr style="background-color:#F2F5F9;">
                                <td><?php echo $tempService->getServiceName(); ?></td>
                                <td><?php echo $tempServingSince; ?></td>
                            </tr>
                        <?php
                            }
                        }

                        if (count($consultantServices) == 0) {
                        ?>
                        <tr>
                            <td colspan="2" style="text-align:center;">Not Provided</td>
                        </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                </table>
            </div>
            <div style="float:left;padding-top:10px;">
                <div style="float:left;font-size:12px;font-weight:bold;padding-bottom:2px;">Services Offered Description:</div>
                <div style="float:left;font-size:12px;padding:5px;border:1px solid #CCCCCC;width:620px;">
                    <?php echo ($user->getServicesOfferedDescription() == "") ? "Not Provided" : $user->getServicesOfferedDescription() ?>
                </div>
            </div>
        </div>
    </div>
    <div style="padding-top:10px;float:left;">
        <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Provided Services To:</div>
        <div style="font-size:12px;padding:5px;border:1px solid #CCCCCC;width:660px;">
            K-12 (e.g., ISDs, private schools): <?php echo ($user->getK12ClienteleIndicator() == "1") ? '<span style="color:green;font-weight:bold;">YES</span>' : '<span style="color:red;font-weight:bold;">NO</span>'; ?>
            <br /><br />
            Higher Education (e.g., junior colleges) : <?php echo ($user->getHigherEducationClienteleIndicator() == "1") ? '<span style="color:green;font-weight:bold;">YES</span>' : '<span style="color:red;font-weight:bold;">NO</span>'; ?>
        </div>
    </div>
    <div style="padding-top:10px;float:left;">
        <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Background:</div>
        <div style="font-size:12px;padding:5px;border:1px solid #CCCCCC;width:660px;">
            <?php echo ($user->getBackgroundDescription() == "") ? "Not Provided" : $user->getBackgroundDescription() ?>
        </div>
    </div>
    <div style="padding-top:10px;float:left;">
        <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Education:</div>
        <div style="font-size:12px;padding:5px;border:1px solid #CCCCCC;width:660px;">
            <?php echo ($user->getEducationDescription() == "") ? "Not Provided" : $user->getEducationDescription() ?>
        </div>
    </div>
    <div style="padding-top:10px;float:left;">
        <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Experience:</div>
        <div style="font-size:12px;padding:5px;border:1px solid #CCCCCC;width:660px;">
            <?php echo ($user->getExperienceDescription() == "") ? "Not Provided" : $user->getExperienceDescription() ?>
        </div>
    </div>
    <div style="padding-top:10px;padding-bottom:20px;float:left;">
        <div style="font-size:12px;font-weight:bold;padding-bottom:2px;">Complaints and / or Litigation:</div>
        <div style="font-size:12px;padding:5px;border:1px solid #CCCCCC;width:660px;">
            Please contact this consultant for more information regarding any pending complaints or litigation.
            <br /><br />
            Complaints: <?php echo ($user->getComplaintIndicator() == "1") ? '<span style="color:green;font-weight:bold;">YES</span>' : '<span style="color:red;font-weight:bold;">NO</span>'; ?>
            <br /><br />
            Litigation: <?php echo ($user->getPendingLitigationIndicator() == "1") ? '<span style="color:green;font-weight:bold;">YES</span>' : '<span style="color:red;font-weight:bold;">NO</span>'; ?>
        </div>
    </div>
</div>